import uniRequest from 'uni-request';

const apiBaseUrl = 'https://openapi.keyboardadmin.com:1986';

// 封装请求服务
const requestService = async (endpoint, method = 'POST', data = null) => {
	const config = {
		url: `${apiBaseUrl}${endpoint}`,
		method,
		data,
		header: {
			'Content-Type': 'application/json'
		}
	};

	try {
		const response = await uniRequest(config);
		return response.data; // 返回请求成功的数据
	} catch (error) {
		console.error('请求错误：', error);
		throw error; // 如果请求失败，抛出错误
	}
};

export default requestService;